import 'package:flutter/material.dart';
import 'package:jd_flutter/base/widget/basic/base_gesture.dart';

class JDScrollView extends StatelessWidget {
  const JDScrollView({
    super.key,
    required this.children,
    this.padding,
    this.physics = const BouncingScrollPhysics(),
    this.crossAxisAlignment = CrossAxisAlignment.start,
    this.bottomWidget,
    this.needDismissKeyBord = false,
    this.scrollController,
  });

  final bool needDismissKeyBord;
  final List<Widget> children;
  final EdgeInsetsGeometry? padding;
  final ScrollPhysics physics;
  final CrossAxisAlignment crossAxisAlignment;
  final Widget? bottomWidget;
  final ScrollController? scrollController;

  @override
  Widget build(BuildContext context) {
    Widget contents = SingleChildScrollView(
      padding: padding,
      physics: physics,
      controller: scrollController,
      keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
      child: Column(
        crossAxisAlignment: crossAxisAlignment,
        children: children,
      ),
    );

    if (needDismissKeyBord) {
      contents = DismissKeyBord(child: contents);
    }

    if (bottomWidget != null) {
      contents = Column(
        children: <Widget>[
          Expanded(child: contents),
          bottomWidget!,
        ],
      );
    }

    return contents;
  }
}
